package com.ruoyi.ams.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.ams.domain.AmsAssetRepairRecordDetail;
import com.ruoyi.ams.service.IAmsAssetRepairRecordDetailService;
import com.ruoyi.common.core.domain.KeyValueVo;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.security.annotation.PreAuthorize;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * 维修明细Controller
 * 
 * @author yfkj
 * @date 2022-05-16
 */
@RestController
@RequestMapping("/ams/repairRecordDetail")
public class AmsAssetRepairRecordDetailController extends BaseController
{
    @Autowired
    private IAmsAssetRepairRecordDetailService amsAssetRepairRecordDetailService;

    /**
     * 查询维修明细列表
     */
    @PreAuthorize
    //@PreAuthorize(hasPermi = "ams:detail:list")
    //@ApiOperation(value = "获取维修明细列表")
    @GetMapping("/getAmsAssetRepairRecordDetailList")
    public TableDataInfo getAmsAssetRepairRecordDetailList(AmsAssetRepairRecordDetail amsAssetRepairRecordDetail)
    {
        startPage();
        List<AmsAssetRepairRecordDetail> list = amsAssetRepairRecordDetailService.selectAmsAssetRepairRecordDetailList(amsAssetRepairRecordDetail);
        return getDataTable(list);
    }


    /**
     * 获取维修明细详细信息
     */
    @PreAuthorize
    //@PreAuthorize(hasPermi = "ams:detail:query")
    @ApiOperation(value = "获取维修明细详情")
    @GetMapping(value = "/getAmsAssetRepairRecordDetailById")
    public AjaxResult getAmsAssetRepairRecordDetailById(@RequestParam("repairRecordId") Long repairRecordId)
    {
        return AjaxResult.success(amsAssetRepairRecordDetailService
                .getOne(new QueryWrapper<AmsAssetRepairRecordDetail>()
                        .eq(AmsAssetRepairRecordDetail.REPAIR_RECORD_ID, repairRecordId), false));
    }

    /**
     * 新增维修明细
     */
    @PreAuthorize
    //@PreAuthorize(hasPermi = "ams:detail:add")
    @Log(title = "维修明细", businessType = BusinessType.INSERT)
    //@ApiOperation(value = "新增维修明细")
    @PostMapping(value = "/addAmsAssetRepairRecordDetail")
    public AjaxResult addAmsAssetRepairRecordDetail(@RequestBody AmsAssetRepairRecordDetail amsAssetRepairRecordDetail)
    {
        return toAjax(amsAssetRepairRecordDetailService.insertAmsAssetRepairRecordDetail(amsAssetRepairRecordDetail));
    }

    /**
     * 修改维修明细
     */
    @PreAuthorize
    //@PreAuthorize(hasPermi = "ams:detail:edit")
    @Log(title = "维修明细", businessType = BusinessType.UPDATE)
    //@ApiOperation(value = "修改维修明细")
    @PostMapping(value = "/editAmsAssetRepairRecordDetail")
    public AjaxResult editAmsAssetRepairRecordDetail(@RequestBody AmsAssetRepairRecordDetail amsAssetRepairRecordDetail)
    {
        return toAjax(amsAssetRepairRecordDetailService.updateAmsAssetRepairRecordDetail(amsAssetRepairRecordDetail));
    }

    /**
     * 删除维修明细
     */
    @PreAuthorize
    //@PreAuthorize(hasPermi = "ams:detail:remove")
    @Log(title = "维修明细", businessType = BusinessType.DELETE)
	@GetMapping("/removeAmsAssetRepairRecordDetails")
    public AjaxResult removeAmsAssetRepairRecordDetails(@RequestParam Long[] repairRecordDetailIds)
    {
        return toAjax(amsAssetRepairRecordDetailService.deleteAmsAssetRepairRecordDetailByRepairRecordDetailIds(repairRecordDetailIds));
    }
    @GetMapping("/getAmsAssetRepairRecordDetailNamesForSelect")
    //@ApiOperation(value = "获取维修明细名称列表用于下拉搜索")
    public AjaxResult getAmsAssetRepairRecordDetailNamesForSelect()
    {
        List<AmsAssetRepairRecordDetail> list = amsAssetRepairRecordDetailService.list();//自行加条件
        List<KeyValueVo> resultList = new ArrayList<>();
        for (AmsAssetRepairRecordDetail amsAssetRepairRecordDetail: list ) {
            KeyValueVo vo = new KeyValueVo();
            //vo.setKey(it.getId());
            //vo.setValue(it.getName());
            resultList.add(vo);
        }
        return AjaxResult.success(resultList);
    }
    /**
     * 导出维修明细列表
     */
    @PreAuthorize
    //@PreAuthorize(hasPermi = "ams:detail:export")
    @Log(title = "维修明细", businessType = BusinessType.EXPORT)
    @PostMapping("/exportAmsAssetRepairRecordDetail")
    public String exportAmsAssetRepairRecordDetail(HttpServletResponse response, AmsAssetRepairRecordDetail amsAssetRepairRecordDetail) throws IOException
    {
        List<AmsAssetRepairRecordDetail> list = amsAssetRepairRecordDetailService.selectAmsAssetRepairRecordDetailList(amsAssetRepairRecordDetail);
        ExcelUtil<AmsAssetRepairRecordDetail> util = new ExcelUtil<AmsAssetRepairRecordDetail>(AmsAssetRepairRecordDetail.class);
        util.exportExcel(response, list, "维修明细数据");
        return "";
    }

}
